package com.yan.handlers;

import com.yan.base.AlertRule;
import com.yan.base.ApiStatInfo;
import com.yan.base.Notification;
import com.yan.base.NotificationEmergencyLevel;

/**
 * @author yanheng
 * @data 2019/12/31 17:10
 */
public class TpsAlertHandler extends AlertHandler {
    public TpsAlertHandler(AlertRule rule, Notification notification) {
        super(rule, notification);
    }

    @Override
    public void check(ApiStatInfo apiStatInfo) {
        long tps = apiStatInfo.getRequestCount() / apiStatInfo.getDurationOfSeconds();
        if (tps > rule.getMatchedRule(apiStatInfo.getApi()).getMaxTps()){
            notification.notify(NotificationEmergencyLevel.URGENCY, "...");
        }
    }
}
